import dayjs from 'dayjs'
export default [
  {
    type: 'selection',
    width: 60,
    align: 'center',
    hidden: true
  },
  {
    title: '标题',
    key: 'title',
    minWidth: 200,
    ellipsis: true,
    tooltip: true,
    search: {
      type: 'input'
    }
  },
  {
    title: '创建时间',
    key: 'created',
    width: 180,
    align: 'center',
    // 方法二：使用 render 方法结构化数据
    render: (h, params) => {
      return h('div', [
        h('span', dayjs(params.row.created).format('YYYY-MM-DD HH:mm:ss'))
      ])
    },
    search: {
      type: 'date'
    }
  },
  {
    title: '作者',
    key: 'user',
    width: 120,
    align: 'center',
    // 方法二：使用 render 方法结构化数据
    render: (h, params) => {
      return h('div', [h('span', params.row.uid.name)])
    },
    search: {
      type: 'input'
    }
  },
  {
    title: '分类',
    key: 'catalog',
    width: 100,
    align: 'center',
    render: (h, params) => {
      const catalog = params.row.catalog
      let result = ''
      switch (catalog) {
        case 'ask':
          result = '提问'
          break
        case 'advise':
          result = '建议'
          break
        case 'discuss':
          result = '交流'
          break
        case 'share':
          result = '分享'
          break
        case 'logs':
          result = '动态'
          break
        case 'notice':
          result = '公告'
          break
        default:
          result = '全部'
      }
      return h('div', [h('span', result)])
    },
    search: {
      type: 'select',
      options: [
        {
          key: '提问',
          value: 'ask'
        },
        {
          key: '建议',
          value: 'advise'
        },
        {
          key: '交流',
          value: 'discuss'
        },
        {
          key: '分享',
          value: 'share'
        },
        {
          key: '公告',
          value: 'notice'
        }
      ]
    }
  },
  {
    title: '积分',
    key: 'fav',
    width: 100,
    align: 'center',
    hidden: true
  },
  {
    title: '标签',
    key: 'tags',
    width: 120,
    align: 'center',
    render: (h, params) => {
      return h('div', [
        h('span', params.row.tags.map((o) => o.name).join(',') || '')
      ])
    },
    search: {
      type: 'input'
    }
  },
  {
    title: '是否结束',
    key: 'isEnd',
    width: 100,
    align: 'center',
    render: (h, params) => {
      return h('div', [h('span', params.row.isEnd === '0' ? '否' : '是')])
    },
    search: {
      type: 'radio'
    }
  },
  {
    title: '阅读记数',
    key: 'reads',
    width: 100,
    align: 'center',
    hidden: true
  },
  {
    title: '回答记数',
    key: 'answer',
    width: 100,
    align: 'center',
    hidden: true
  },
  {
    title: '状态',
    key: 'status',
    width: 120,
    align: 'center',
    render: (h, params) => {
      return h('div', [
        h('Tag', {
          class: 'test',
          props: {
            color: params.row.status === '0' ? 'success' : 'error'
          },
          domProps: {
            innerHTML: params.row.status === '0' ? 'on' : 'off'
          }
        })
      ])
    },
    search: {
      type: 'radio'
    }
  },
  {
    title: '是否置顶',
    key: 'isTop',
    width: 100,
    align: 'center',
    render: (h, params) => {
      return h('div', [
        h('Icon', {
          props: {
            color: '#19be6b',
            type: params.row.isTop === '1' ? 'md-checkmark' : '',
            size: 20
          }
        })
      ])
    },
    search: {
      type: 'radio'
    }
  },
  {
    slot: 'action',
    title: '设置',
    key: 'settings',
    fixed: 'right',
    width: 160,
    align: 'center',
    hidden: true
  }
]
